import React, {useEffect, useState} from 'react';
import {TreeSelect} from "antd";
import {useParams} from "react-router-dom";
import {getDepartmentByHoscode} from "@/api/hosp";
const {TreeNode} = TreeSelect;
function Index() {
    const {hoscode} = useParams();
    type TTreeNode = typeof TreeNode;
    // 用于保存科室列表的状态
    const [departmentList,setDepartmentList] = useState([]);
    useEffect(()=>{
        getDepartmentByHoscode(hoscode as string).then(value=>{
            console.log(value);
            setDepartmentList(value.data);
        })
    },[]);
    return (
        <div id={"content"}>
            <TreeSelect
                showSearch
                style={{ width: '100%' }}
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                // filterTreeNode={(inputValue: string, treeNode: TTreeNode)=>{
                //     // console.log(inputValue);
                //     return false;
                // }}
                filterTreeNode = {(inputValue:string,treeNode:any)=>{
                    console.log(inputValue,treeNode);
                    return treeNode.title.includes(inputValue);
                }}
                placeholder="请选择科室"
                allowClear
                treeDefaultExpandAll={false}
                onChange={()=>{

                }}
            >
                {
                    departmentList.map((item:any)=>(
                        <TreeNode selectable={false} key={item.depcode} value={item.depcode} title={item.depname}>
                            {
                                item.children.map((item:any)=>(
                                    <TreeNode key={item.depcode} value={item.depcode} title={item.depname}></TreeNode>
                                ))
                            }
                        </TreeNode>
                    ))
                }
                {/*<TreeNode value="parent 1" title="parent 1">*/}
                {/*    <TreeNode value="parent 1-0" title="parent 1-0">*/}
                {/*        <TreeNode value="leaf1" title="leaf1" />*/}
                {/*        <TreeNode value="leaf2" title="leaf2" />*/}
                {/*    </TreeNode>*/}
                {/*    <TreeNode value="parent 1-1" title="parent 1-1">*/}
                {/*        <TreeNode value="leaf3" title={<b style={{ color: '#08c' }}>leaf3</b>} />*/}
                {/*    </TreeNode>*/}
                {/*</TreeNode>*/}
            </TreeSelect>
        </div>
    );
}

export default Index;